import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import WindiCSS from 'vite-plugin-windicss'
import ViteComponents from 'vite-plugin-components';
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
// const isProduction = process.env.NODE_ENV === 'production'

export default defineConfig({
  base: process.env.ELECTRON=="true" ? './' : "",
  plugins: [vue(), WindiCSS(),
    Components({
      dirs: ["@/components"],
      extensions: ["vue"],
      dts: "src/components.d.ts",
    }),
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
        /\.md$/, // .md
      ],
      imports: [
        "vue",
        "@vueuse/core",
        {
          "@/store/modules/user": ["useUserStore"],
          "@/store/modules/theme": ["useThemeStore"],
          "@/http": ["httpClient"],
          "@/api": ["indexApi"],
        },
      ],
      dts: "src/auto-import.d.ts",
    }),
    ViteComponents({
    }),
  ],
  // 项目根目录
  root: process.cwd(),
  // 在生产中服务时的基本公共路径
  // base: isProduction ? './' : '',
  // 配置中指明将会把 serve 和 build 时的模式都覆盖掉,serve 时默认 'development'，build 时默认 'production'
  mode: 'development',
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"), // 路径别名
    },
    extensions: [".js", ".json", ".ts"], // 使用路径别名时想要省略的后缀名，可以自己 增减
  },
  server:{
    proxy:{
     '/node-base': {
        target: 'http://localhost:3000',
        ws: true, changeOrigin: true,
        rewrite: (path) => path.replace(/^\/node-base/, '')
      }
    }
  }
})
